package cn.edu.cqu.android.phone.sms;

import java.io.UnsupportedEncodingException;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

import cn.edu.cqu.android.phone.domain.Users;
import cn.edu.cqu.android.phone.loaddata.OldDataSource;
import cn.edu.cqu.android.phone.loaddata.Schema;


public class Test {

	/**
	 * @param args
	 * @throws ClassNotFoundException 
	 * @throws SQLException 
	 * @throws UnsupportedEncodingException 
	 */
	public static void main(String[] args) throws ClassNotFoundException, SQLException, UnsupportedEncodingException {
		// TODO Auto-generated method stub
//		Class.forName("org.sqlite.JDBC");
//		Connection conn = DriverManager.getConnection("jdbc:sqlite:db/mmssms.db");
//		Statement stat = conn.createStatement();
//		ResultSet rs=stat.executeQuery("select * from sms");
//		while(rs.next()){
//				System.out.println(new String(rs.getBytes("body"),"UTF-16"));
//		}
		AnnotationConfiguration cfg;
		cfg=new AnnotationConfiguration();
//		cfg.configure();
		cfg.configure("/hibernate.cfg.xml");
		SessionFactory sf=cfg.buildSessionFactory();
		Session s=sf.openSession();
		s.beginTransaction();
		Users user=(Users) s.get(Users.class, 1);
		OldDataSource oldDataSource=new OldDataSource(Schema.OLDURL4SMS);
		oldDataSource.connect();
		oldDataSource.addSms(user, s, new Date(0));
		oldDataSource.close();
		try{
			s.getTransaction().commit();
		}catch(Exception e){
			e.printStackTrace();
			s.getTransaction().rollback();
		}finally{
			s.close();
		}
		sf.close();
	}

}
